Frogger
Working with just the Bar class:
- Get bar to move (this will only happen when keys are pressed
- Get bar to screen wrap or bounce
- Get bar to have a random speed (so speed should be a global)
- Get bar to have a random color
- Get a random direction:
- Create a global variable boolean isMovingRight
- In the constructor (public Bar(int y){
- make global isMovingRight randomly left (false) or right (true)
Working with the BarTester
- Make another Bar - bar2 and move and draw that
- Make it an array of Bars do either [1 is easier]
- Bar allBars[]={new Bar(100),new Bar(200), ....}
- or Bar allBars[5]=new Bar[5]; then allBars[0]=new Bar(20); etc
- Then move and draw each one:
for (int i=0; i<allBars.length; i++)
{
allBars[i].moveBar();
allBars[i].drawBar(g);
//check for collissions
}
Working with Frogger
- Move stuff from BarTester in to Frogger (stuff that creates an array of bars and moves, draws them
- Work with Frog
- Get move to work
- Add collission to the bar class
Changing sprites to use images is really easy, which just load the image with the constructor
- super(50,100,20,30, "mario.jpg");
Sprite has a build in method: drawImage(g) that will automatically draw the image at g. So in the main Frogger class, if Frog had an image loaded:
- myFrog.drawImage(g); //would call the drawImage of sprite
|